package com.ruoyi.delivery.controller;

import com.ruoyi.delivery.domain.DelOperatorTransportDetail;
import com.ruoyi.delivery.domain.DelOperatorTransportOrder;
import com.ruoyi.delivery.domain.DelTransportDetail;
import com.ruoyi.delivery.service.IDelOperatorTransportDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 运输订单明细信息 控制层
 *
 * @author skye
 */

@RestController
@RequestMapping("/delivery/operatorTransportDetail")
public class DelOperatorTransportDetailController {

    @Autowired
    private IDelOperatorTransportDetailService operatorTransportDetailService;

    /**
     * 根据 trackingNumber 获取所有运单明细
     * @param trackingNumber 运单号
     * @return 运单明细列表
     */
    @RequestMapping
    public List<DelOperatorTransportDetail> getDetailsByTrackingNumber(String trackingNumber) {
        return operatorTransportDetailService.getDetailsByTrackingNumber(trackingNumber);
    }

    @PostMapping("/addDetail")
    public Map<String, Object> addOperatorTransportDetail(@RequestBody DelOperatorTransportDetail detail) {
        boolean success = operatorTransportDetailService.insertOperatorTransportDetail(detail);
        Map<String, Object> response = new HashMap<>();
        response.put("success", success);
        return response;
    }

    @RequestMapping("/filter/{trackingNumber}")
    public List<DelOperatorTransportDetail> searchOperatorTransportDetails(
            String productName,
            String orderNumber,
            String productBatch, @PathVariable String trackingNumber) {
        return operatorTransportDetailService.searchOperatorTransportDetails(trackingNumber,productName, orderNumber, productBatch);
    }

    @RequestMapping("/order/{orderNumber}")
    public List<DelOperatorTransportDetail> getDetailsByOrderNumber(@PathVariable("orderNumber") String orderNumber) {
        return operatorTransportDetailService.getDetailsByOrderNumber(orderNumber);
    }
}
